POV-Ray : Newsgroups : povray.programming : C++ problem : Re: C++ problem Server Time
28 Jul 2024 14:34:45 EDT (-0400)
  Re: C++ problem  
From: Warp
Date: 28 Jul 2001 20:23:15
Message: <3b635773@news.povray.org>
In povray.unix Thorsten Froehlich <tho### [at] trfde> wrote:
: Well, this can be true in case virtual functions are added to a class
: containing no virtual functions (and the compiler optimized away the storage
: for the vtable pointer if it wasn't used) and when inheriting from other
: class(es) class sizes can grow because of vtables and different
: this-pointers.

  I didn't mean this. I meant that they think that a class with 20 methods
takes more space than a class with 10 methods.

  Of course making the class virtual increases its size (in practice by
the size of a pointer). It doesn't matter, however, how many virtual
functions you put inside it, it will not take any extra space.

: Of course, you assume the vtable is in the cache and the processor supports
: the necessary indirect addressing modes.

  If the vtable isn't in the cache, then the function to be called will
probably not be either, so it usually doesn't make that big difference
(compared to a non-virtual function, I mean).

  Of course one has to be aware of the fact that virtual classes are not
totally free. Usually it's not a good idea to make a method virtual just
for the sake of it, specially if it's time-critical. Also making a class
virtual just for the sake of it may not be a good idea if space is a critical
issue (eg. the class itself is very small and millions of instances are
created from that class).
  Using virtual functions in a class increases the size of the class (usually
by one pointer). With very space-critical classes this has to be noted.
  Calling a virtual function can be a bit slower than a regular function,
although it usually isn't considerable slowdown.
  Virtual functions most probably can't be inlined (although this is one
detail where I'm not 100% sure).

  Virtual inheritance is a story on its own...

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.